<?php
///**
// * Created by PhpStorm.
// * User: Administrator
// * Date: 2017/10/17
// * Time: 14:36
// */
//namespace  app\api\exception;
//use think\exception\Handle;
//use think\exception\HttpException;
//
//class Http extends Handle
//{
//    public function render(Exception $e)
//    {
//        if($e instanceof  HttpException){
//            $statsCode = $e->getStatusCode();
//        }
//
//        if(!isset($statsCode)){
//            $statsCode = 500;
//        }
//
//        $result = [
//            'code' => $statsCode,
//            'msg' => $e->getMessage(),
//            'code' => $_SERVER['REQUEST_TIME'],
//        ];
//        return json($result,$statsCode);
//    }
//}

namespace app\api\exception;
use think\exception\Handle;
use think\exception\HttpException;
class Http extends Handle
{
    public function render(\Exception $e)
    {
        if ($e instanceof HttpException) {
            $statusCode = $e->getStatusCode();
        }
        if (!isset($statusCode)) {
$statusCode = 500;
}
$result = [
    'code' => $statusCode,
    'msg' => $e->getMessage(),
    'time' => $_SERVER['REQUEST_TIME'],
];
return json($result, $statusCode);
}
}